<?php
error_reporting(7);

if (!$_GET['action'] AND !$_POST['action']) {
        $_GET['action'] = "view";
}

if($_GET['action']=="add"){
    require "common.php";
    require "tools/news/class.news.php";
    $news=new NEWS($DB);
    $id=$_POST["id"];
    $title=$_POST["title"];
    $catetree=$_POST["catetree"];
    $sort=$_POST["sort"];
    $content=$_POST["content"];
    $result=$news->add($id,$title,$catetree,$sort,$content);

    redirect("./news.php?action=view", "添加成功！");
}
if($_GET['action'] == "addview"){
    $template_name = "news_add.htm";
    require "common.php";
    ///*****生成分类数据////
    require_once "tools/tree/sort.class.php";
    $tree = new SortClass($DB,'`t_reported_sys`');
    $selecttreelist=$tree->makeTreeSelect(66,"catetree");
    ///*****生成分类数据结束////
    $tpl->assign("selecttreelist",$selecttreelist);
    $tpl->output();
}

if($_GET['action'] == "editview"){
    $template_name = "news_edit.htm";
    require "common.php";
    require "tools/news/class.news.php";
    ///*****生成分类数据////
    require_once "tools/tree/sort.class.php";
    $tree = new SortClass($DB,'`t_reported_sys`');
    $selecttreelist=$tree->makeTreeSelect(66,"catetree");
    ///*****生成分类数据结束////
    $news=new NEWS($DB);
    $result=$news->getNewsByid($_GET['id']);
    $tpl->assign("selecttreelist",$selecttreelist);
    $tpl->assign($result);
    $tpl->output();
} 

if ($_GET[action] == "remove") {
        require "common.php"; 
        // START 检查权限
        if (!$perm->check_permission(NEWS, NEWS_WRITE)) {
                display_nopermission();
        }
        // END 检查权限
        $id=$_GET["id"];
        require "tools/news/class.news.php";
        $news=new NEWS($DB);
        $result=$news->del($id);
        if($result){
            redirect("javascript:window.history.back()", "删除成功！");
        }else{
            redirect("javascript:window.history.back()", "删除失败！");
        }

}

if ($_GET[action] == "view") {
        $template_name = "news_view.htm";
        require "common.php";
        require "tools/news/class.news.php";
        $cate=$_GET["catetree"];
        $title=$_GET["title"];
        $type=$_GET["type"];
        $add_time=$_GET["add_time"];
        $operator=$_GET["operator"];
        // START 检查权限
        if (!$perm->check_permission(NEWS, NEWS_VIEW)) {
                display_nopermission();
        }
        // END 检查权限
        ///*****生成分类数据////
        require_once "tools/tree/sort.class.php";
        $tree = new SortClass($DB,'`t_reported_sys`');
        $selecttreelist=$tree->makeTreeSelect(66,"catetree");
        ///*****生成分类数据结束////

        if(!empty($cate)){
            $where.=" and cate='$cate'";
        }
        if(!empty($type)){
            $where.=" and type='$type'";
        }
        if(!empty($title)){
            $where.=" and title like '%$title%'";
        }
        if(!empty($add_time)){
            $where.=" and add_time>'$add_time'";
        }
        if(!empty($operator)){
            $where.=" and operator='$operator'";
        }
        $news=new NEWS($DB);
        $result=$news->show($where);
        $tpl->assign($news->pager->result);
        $tpl->assign("selecttreelist",$selecttreelist);
        $tpl->assign("results", $result);
        $tpl->output();
}

?>